package org.goldenmock.web.util;

import org.easymock.EasyMock;
import org.goldenmock.web.matchers.*;
import org.goldenmock.web.server.*;

/**
 * This utility class should really be static imported so that
 * it's possible to write consise tests
 *
 * @author Robin Wagenaar
 * @author Arjen van Staalduinen
 */
@SuppressWarnings(value = {"SameReturnValue", "unused"})
public class HttpMockUtils {

    public static <T extends EasyHttpRequest> T contentContains(String pattern) {
        EasyMock.reportMatcher(new ContentRegexMatcher(".*" + pattern + ".*"));
        return null;
    }

    public static <T extends EasyHttpRequest> T contentMatchesRegex(String pattern) {
        EasyMock.reportMatcher(new ContentRegexMatcher(pattern));
        return null;
    }

    public static <T extends EasyHttpRequest> T contentMatchesXPath(String xpathExpression, String expectedValue) {
        EasyMock.reportMatcher(new ContentXPathMatcher(xpathExpression, expectedValue));
        return null;
    }

    public static <T extends EasyHttpRequest> T uriContains(String pattern) {
        EasyMock.reportMatcher(new RequestUriMatcher(".*" + pattern + ".*"));
        return null;
    }

    public static <T extends EasyHttpRequest> T paramExists(String key) {
        EasyMock.reportMatcher(new RequestParamExistsMatcher(key));
        return null;
    }

    public static <T extends EasyHttpRequest> T paramHasValue(String key, String value) {
        EasyMock.reportMatcher(new RequestParamEqualsMatcher(key, value));
        return null;
    }

    public static <T extends EasyHttpRequest> T uriMatches(String pattern) {
        EasyMock.reportMatcher(new RequestUriMatcher(pattern));
        return null;
    }

    public static <T extends EasyHttpRequest> T headersContain(String headerType, String headerValue) {
        EasyMock.reportMatcher(new HeadersContainMatcher(headerType, headerValue));
        return null;
    }

    public static <T extends EasyHttpRequest> T requestMethodMatches(String requestMethod) {
        EasyMock.reportMatcher(new RequestMethodMatcher(requestMethod));
        return null;
    }

    public static HttpServerInterface createServerMock(int port) {
        return HttpServerWrapper.create(port);
    }

    public static void stopServerMock(int port) {
        HttpServerWrapper.kill(port);
    }

    public static EasyHttpResponseBuilder response() {
        return new EasyHttpResponseBuilder();
    }
}
